////
////  ContainerPickControllerTableViewController.swift
////  Wmsmobile
////
////  Created by Nick xu on 16/7/28.
////  Copyright © 2016年 hddden. All rights reserved.
////
//
//import UIKit
//import SVProgressHUD
//fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
//  switch (lhs, rhs) {
//  case let (l?, r?):
//    return l < r
//  case (nil, _?):
//    return true
//  default:
//    return false
//  }
//}
//
//fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
//  switch (lhs, rhs) {
//  case let (l?, r?):
//    return l > r
//  default:
//    return rhs < lhs
//  }
//}
//
//fileprivate func <= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
//  switch (lhs, rhs) {
//  case let (l?, r?):
//    return l <= r
//  default:
//    return !(rhs < lhs)
//  }
//}
//
//
//
//
//class ContainerPickController: UITableViewController, UITextFieldDelegate,FounctionBottomViewDelegate,normalInputViewStateProtocol , UIGestureRecognizerDelegate {
//    
//    //MARK: - property
//    var cellDictionary:[String : FounctionBaseCell] = [String : FounctionBaseCell]()
//    var reuseAble: Bool = true
//    var allInfo: [String : String] = ["piOperator" : (userInfo?.userName)!, "piUser" : (userInfo?.userName)! , "piType" : "0"]
//    var bottomItems:Array<Dictionary<String , String>>?
//    var dataArray:Array<[[String:String]]>?
//    var inputCellArray:Array<inputViewProtocol> = [inputViewProtocol]() //记录需要激活的cell
//    var displayCellArray:Array<displayDetailProtocol> = [displayDetailProtocol]() //记录需要展示数据的cell
//    var firstIndexPath:IndexPath?
//    var sectionHeaders: [String]?
//    var sectionFooters: [String]?
//    var controllerInfo: AnyObject?
//    var dictCollections:[String : [[String : String]]]?
//    var DetailListCellIndexPath:[IndexPath] = [IndexPath]()
//    var firstAppear: Bool = true //记录是不是第一次加载，
//    weak var savedGestureRecognizerDelegate:UIGestureRecognizerDelegate?
//    weak var activedCell: FounctionBaseCell?
//    var model: YunCangModel?
//    weak var messageView: MessageView?
//    lazy fileprivate var favoriteButton:UIButton = {
//        let button = UIButton(frame: CGRect(x: KscreenWidth - 54, y: 0, width: 44, height: 44))
//        button.setImage(UIImage(named: "收藏home"), for: UIControlState())
//        button.setImage(UIImage(named: "收藏icon"), for: UIControlState.selected)
//        return button
//    }()
//
//    //MARK: - lifecycle
//    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
//        super.init(nibName: nil, bundle: nil)
//    }
//    convenience init(info:AnyObject? , model: YunCangModel) {
//        self.init()
//        self.model = model
//        self.controllerInfo = info
//        let originArray = info!["dataArray"]
//        self.bottomItems = info!["bottom"] as? Array<Dictionary<String , String>>
//        self.sectionHeaders = info!["sectionHeaders"] as? [String]
//        self.sectionFooters = info!["sectionFooters"] as? [String]
//        if let array = originArray as? Array<[[String:String]]>{
//             self.dataArray = array
//        }
//        let string = info!["firstIndexPath"] as? String
//        if let indexStringArray = string?.components(separatedBy: ",") {
//            let section = Int((indexStringArray.first)!)
//            let row = Int((indexStringArray.last)!)
//            self.firstIndexPath = IndexPath(row: row!, section: section!)
//        }
//        if  let dict = self.controllerInfo?["collectionInfo"]  {
//            
//            if let indexPathStrings = (dict as? [String : Any])?["collectionindexs"] as? [String]{
//                for string in indexPathStrings {
//                    let intArray:[String] = string.components(separatedBy: ",")
//                    let row:Int = Int(intArray[1])!
//                    let section:Int = Int(intArray[0])!
//                    let indexPath = IndexPath(row: row, section: section)
//                    self.DetailListCellIndexPath.append(indexPath)
//                }
//            }
//        }
//        
//
//    }
//    init(){
//        super.init(style: UITableViewStyle.grouped)
//    }
//    
//    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
//    override func viewDidLoad() {
////         let leftItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem., target: self, action: #selector(ContainerPickController.clickReturnButton(_:)))
//        let leftItem = UIBarButtonItem(image: UIImage(named: "返回"), landscapeImagePhone: UIImage(named: "返回"), style: UIBarButtonItemStyle.plain, target: self, action: #selector(ContainerPickController.clickReturnButton(_:)))
//        self.tableView.contentInset.bottom = self.bottomView == nil ? 0 : FBVButtonHeight
//        self.tableView.rowHeight = 44
//        self.navigationItem.leftBarButtonItem = leftItem
//        self.view.backgroundColor = UIColor.hexStringToUIColor("#eeeeee")
//        tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 10))
//        if self.bottomView != nil {
//            self.view.addSubview(self.bottomView!)
//            self.bottomView!.delegate = self
//            self.bottomView!.isUserInteractionEnabled = true
//        }
//        self.tableView.allowsSelection = false
////        self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0)
//        let tap = UITapGestureRecognizer(target: self, action: #selector(ContainerPickController.tapOnTableView))//添加点击回收键盘的tap手势
//        self.tableView.addGestureRecognizer(tap)
//        self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissMode.onDrag//回收逻辑，滚动回收
////        self.tableView.separatorStyle = .SingleLine
//        //注册通知，接受日期选择结束的通知
//        NotificationCenter.default.addObserver(self, selector: #selector(ContainerPickController.finishDateInput(_:)), name: NSNotification.Name(rawValue: "dateInputDone"), object: nil)
//
//        self.favoriteButton.addTarget(self, action: #selector(ContainerPickController.clickFavoriteButton(_:)), for: UIControlEvents.touchUpInside)
//                self.navigationController?.navigationBar.addSubview(favoriteButton)
////        self.navigationItem.rightBarButtonItem = favoriteBarButton
//        self.favoriteButton.isSelected = self.model?.FAVORITES == NSNumber.init(value: 1 as Int) ? true : false
//    }
//    override func viewDidDisappear(_ animated: Bool) {
//        self.view.endEditing(true)
//    }
//    override func viewWillDisappear(_ animated: Bool) {
//      
//        self.view.endEditing(true)
////        let childControllers = self.navigationController?.viewControllers //控制功能模块的子控制器是否带有收藏按钮
////        if let _ = childControllers!.indexOf(self) {
////        }else{
////            favoriteButton.removeFromSuperview() 
////        }
//        favoriteButton.removeFromSuperview()
//        self.messageView?.removeFromSuperview()
//        self.navigationController?.interactivePopGestureRecognizer?.delegate = savedGestureRecognizerDelegate
//    }
//    override func viewWillAppear(_ animated: Bool) {
//        super.viewWillAppear(animated)
////        let favoriteBarButton = UIBarButtonItem(customView: self.favoriteButton)
////        self.favoriteButton.addTarget(self, action: #selector(ContainerPickController.clickFavoriteButton(_:)), forControlEvents: UIControlEvents.TouchUpInside)
//////        self.navigationController?.navigationBar.addSubview(favoriteButton)
////        self.navigationItem.rightBarButtonItem = favoriteBarButton
////        self.favoriteButton.selected = self.model?.FAVORITES == NSNumber.init(long: 1) ? true : false
//
//        savedGestureRecognizerDelegate = self.navigationController?.interactivePopGestureRecognizer?.delegate
//        self.navigationController?.interactivePopGestureRecognizer?.delegate = self
//    }
//    override func viewDidAppear(_ animated: Bool) {
//        super.viewDidAppear(animated)
//        if self.firstAppear == true{
//            let cell = self.tableView.cellForRow(at: self.firstIndexPath!) as! inputViewProtocol
//            cell.state = inputViewState.activated
//            self.firstAppear = false
//            self.activedCell = cell as? FounctionBaseCell
//        }
//    }
//    //MARK: - UIResponse
//    func tapOnTableView() {
////        self.view.endEditing(true)
//    }
//    //MARK: - privte method
//    func clickFavoriteButton(_ button: UIButton){
//       self.favoriteButton.isSelected = !self.favoriteButton.isSelected
//        self.favoriteButton.isEnabled = false
//        NetworkTool.sharedTools.postSoap(["piModule" : self.model!.FMODULENO! , "piFlag" : self.favoriteButton.isSelected ? "1" : "0" , "piOperator" : (userInfo?.userName)!], bodyMethod: "UpdUserUsedModule", suffix: "225", success: { [weak self] (data) in
//            //添加成功
//            if self!.favoriteButton.isSelected {  //添加收藏
//                userInfo?.favoriteItems?.append(self!.model!)
//                self!.model?.FAVORITES = NSNumber.init(value: 1 as Int)
//                self!.showMessage("添加收藏成功", success: true)
//            }else{ //取消收藏
//                self!.showMessage("取消收藏成功", success: true)
//                self!.model?.FAVORITES = NSNumber.init(value: 0 as Int)
//                var indexToUpdate: Int?
//                for i in 00..<(userInfo?.favoriteItems)!.count {
//                    if (userInfo?.favoriteItems)![i] == self!.model {
//                        indexToUpdate = i
//                    }
//                }
//                userInfo?.favoriteItems?.remove(at: indexToUpdate!)
//            }
//            self!.favoriteButton.isEnabled = true
//        }) {
//            //添加失败
//            if self.favoriteButton.isSelected {
//                self.showMessage("添加收藏失败", success: false)
//                self.favoriteButton.isSelected = false
//            }else{
//                self.showMessage("取消收藏失败", success: false)
//                self.favoriteButton.isSelected = true
//            }
//            self.favoriteButton.isEnabled = true
//        }
//    }
//    //执行跳转
//    func goToErrorNextCell(_ cell : FounctionBaseCell){
//        let info = cell.info
//        guard info?["errorNext"] != nil else {
//            (cell as? inputViewProtocol)?.state = inputViewState.disabled
//            return
//        }
//        let indexStringArray = info!["errorNext"]?.components(separatedBy: ",")
//        let section = Int((indexStringArray?.first)!)
//        let row = Int((indexStringArray?.last)!)
//        let indexPath = IndexPath(row: row!, section: section!)
//        let cell = self.activedCell as? inputViewProtocol
//        cell?.state = inputViewState.disabled
//        let nextCell = self.tableView.cellForRow(at: indexPath) as? inputViewProtocol
//        nextCell?.state = inputViewState.wrong
//        self.activedCell = nextCell as? FounctionBaseCell
//
//    }
//    func goToNextCell(_ cell : FounctionBaseCell){
//        let info = cell.info
//        guard info?["next"] != nil else {
//            (cell as? inputViewProtocol)?.state = inputViewState.disabled
//            return
//        }
//        let indexStringArray = info!["next"]?.components(separatedBy: ",")
//        let section = Int((indexStringArray?.first)!)
//        let row = Int((indexStringArray?.last)!)
//        let indexPath = IndexPath(row: row!, section: section!)
//        let cell = cell as? inputViewProtocol
//        cell?.state = inputViewState.disabled
//        let nextCell = self.tableView.cellForRow(at: indexPath) as? inputViewProtocol
//        nextCell?.state = inputViewState.activated
//        self.activedCell = nextCell as? FounctionBaseCell
//    }
//
//    func clickReturnButton(_ button: UIButton){
//        //如果第一个cell是空的，直接返回
//        if let cell = self.tableView.cellForRow(at: self.firstIndexPath!) as? displayDetailProtocol {
//            if cell.isEmpty() {
//                _ = self.navigationController?.popViewController(animated: true)
//                return
//            }
//        }
//       
//        let alertController  = UIAlertController(title: "确认", message: "确定清空所有信息并退出吗？", preferredStyle: UIAlertControllerStyle.alert)
//        let doneAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.default) { [weak self] (done) in
//            _ = self?.navigationController?.popViewController(animated: true)
//        }
//        let cancleAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel) { (cancel) in
//            alertController.dismiss(animated: true, completion: nil)
//        }
//        alertController.addAction(doneAction)
//        alertController.addAction(cancleAction)
//        self.present(alertController, animated: true, completion: nil)
//    }
//    fileprivate func showMessage(_ message: String,success: Bool){
//        let flag:Bool = messageView == nil ? true : false
//        let view = MessageView(onVC: self,message: message, success: success)
//        if self.messageView != nil{
//            view.y = 64
//        }
//        self.messageView?.layer.removeAllAnimations()
//        self.tableView.layer.removeAllAnimations()
//        ContainerPickController.cancelPreviousPerformRequests(withTarget: self, selector: #selector(ContainerPickController.messageAnimation(_ :)), object: self.messageView)
//        self.messageView?.removeFromSuperview()
//        self.messageView = nil
//        self.navigationController?.view.insertSubview(view, at: 1)
//        UIView.animate(withDuration: 0.5, animations: {
//            view.y = 64
//        }) 
//        if flag {
//            UIView.animate(withDuration: 0.5, animations: {
//                if self.tableView.contentSize.height > KscreenHeight - self.tableView.contentInset.top - self.tableView.contentInset.bottom {
//                    self.tableView.contentInset.top = 64 + view.height
//                    self.tableView.contentOffset.y =  self.tableView.contentOffset.y - view.height
//                }else{
//                    self.tableView.contentInset.top = 64 + view.height
//                }
//            }) 
//        }
//        self.messageView = view
//        self.perform(#selector(ContainerPickController.messageAnimation(_ :)), with: view, afterDelay: 2.5)
//    }
//    func messageAnimation(_ messageView: UIView){
//        UIView.animate(withDuration: 0.5, animations: {
//            self.tableView.contentOffset.y = self.tableView.contentOffset.y + messageView.height
////            if self.tableView.contentSize.height > KscreenHeight - self.tableView.contentInset.top - self.tableView.contentInset.bottom {
//                self.tableView.contentInset.top = 64
////            }
//            messageView.y = 24
//        }, completion: { (true) in
//            messageView.removeFromSuperview()
//        }) 
//    }
//    func compareElement(_ releationShip: String,key1: String,key2: String,success:() -> (), failed: () -> ()){
//        let value1 = allInfo[key1]
//        let value2 = allInfo[key2]
//        guard value1 != nil && value2 != nil else {
//            self.showMessage("请完善信息后再试", success: false)
//            return
//        }
//        switch releationShip {
//        case "=":
//            var flag:Bool = false
//            for value in (value2?.components(separatedBy: ","))!{
//                if value1 == value{
//                    success()
//                    flag = true
//                    break
//                }
//            }
//            if !flag {
//                failed()
//                break
//            }
//        case "<":
//            var flag:Bool = false
//            for value in (value2?.components(separatedBy: ","))!{
//                if value1 < value{
//                    success()
//                    flag = true
//                    break
//                }
//                if !flag {
//                    failed()
//                    break
//                }
//            }
//        case ">":
//            var flag:Bool = false
//            for value in (value2?.components(separatedBy: ","))!{
//                if value1 > value{
//                    success()
//                    flag = true
//                    break
//                }
//                if !flag {
//                    failed()
//                    break
//                }
//            }
//        case "<=":
//            var flag:Bool = false
//            for value in (value2?.components(separatedBy: ","))!{
//                if value1 <= value{
//                    success()
//                    flag = true
//                    break
//                }
//                if !flag {
//                    failed()
//                    break
//                }
//            }
//
//        default:
//            failed()
//        }
//    }
//    
//    func oneToManyHandle(_ piArticleCode: String, piOwner: String?, piBin: String?, success:@escaping () -> () , faild:@escaping () -> ()) -> (){ //一码多品处理
//        if let string = piOwner { //piOwner存在就用piOwner查询，不再使用piBin
//            var params = ["piArticleCode" : piArticleCode] //组装参数
//            params.updateValue(string, forKey: "piOwner")
//            NetworkTool.sharedTools.postSoap(params as NSDictionary, bodyMethod: "GetArticleByOwner",suffix: nil, success: { [weak self]
//                
//                (data) in
//                let result = analysisManager.shareManager.XmlParserAnalysis(XMLParser(data: data), elementName: "collect")
//                let resultMsgs = analysisManager.shareManager2.XmlParserAnalysis(XMLParser(data: data), elementName: "GetArticleByOwnerResponse").first!
//                self!.allInfo += resultMsgs
//                guard resultMsgs["GetArticleByOwnerResult"] == "0" else {
//                    faild()
//                    return
//                }
//                if result.count > 1 {
//                    let selectorView = SelectTableView(dataArray: result)
//                    selectorView.showSelector(self!.tableView, success: { [weak self] (dict) in
//                        self!.allInfo += dict
//                        success()
//                    })
//                }else{ //只有一个货物就直接赋值走人
//                    self!.allInfo += result.first!
//                    success()
//                }
//                }, failed: {
//                  faild()
//            })
//        }else{ //piOwner不存在，使用piBin查询
//            var params = ["piArticleCode" : piArticleCode]
//            params.updateValue(piBin!, forKey: "piBin")
//            NetworkTool.sharedTools.postSoap(params as NSDictionary, bodyMethod: "GetArticleByBin",suffix: nil, success: { [weak self]
//                
//                (data) in
//                let result = analysisManager.shareManager.XmlParserAnalysis(XMLParser(data: data), elementName: "collect")
//                let resultMsgs = analysisManager.shareManager2.XmlParserAnalysis(XMLParser(data: data), elementName: "GetArticleByBinResponse").first!
//                self!.allInfo += resultMsgs
//                guard result.count > 0 else {
//                    return
//                }
//                if result.count > 1 {
//                    let selectorView = SelectTableView(dataArray: result)
//                    selectorView.showSelector(self!.tableView, success: { [weak self] (dict) in
//                        self!.allInfo += dict
//                        success()
//                    })
//                }else{ //只有一个货物就直接赋值走人
//                    self!.allInfo += result.first!
//                    success()
//                }
//                }, failed: {
//                    //TODO: //网络请求失败
//                   
//            })
//        }
//    }
//    func requestWithMethodName(_ cell: FounctionBaseCell?, methodNames: [String] ,text: String, index: NSInteger ,skip: Bool,success: (() -> ())?,field:(() -> ())? ){
//        var params = [String : String]()
//        allInfo += (cell?.info)!
//        let methodName = methodNames[index]
//        let soapMethodName = methodName.components(separatedBy: "=").first
//        let dict = ["" : ""] //取出函数名对应的函数详情
//        let suffix = ""
//        /*
//         1.根据methodName取出 取出main参数名
//         2.根据methodName取出 动态参数列表 加入参数字典
//         3.根据methodName取出 固定参数列表 加入参数字典
//         4.按执行网络请求
//         5.多次请求同上
//         */
////        let paramMain = dict["paramMain"] as! String //取出了主参数名
////        if paramMain != ""{
////            params[paramMain] = text //加入到请求参数字典
////            allInfo[paramMain] = text //同时加入allInfo备用
////        }
////        if let destineParams = dict["destineParams"] as? [String : String] {
////            for item in destineParams.keys{
////                if let value = allInfo[destineParams[item]!]{ //取到就OK
////                    params.updateValue(value, forKey: item)
////                    allInfo.updateValue(value, forKey: item)
////                }else{ //强制必须取到值，否则返回
////                    self.showMessage("请完善信息后再试", success: false)
////                    return
////                }
////            }
////        }
//        
//        
//        
//        
//        var paramsOthers = [String]()
//        if let paramOthersTemp = dict["paramOthers"] as? [String]{//取出其他参数名
//            paramsOthers = paramOthersTemp
//        }else{ //参数列表不存在
//            if let giveDefaultValueKey = cell?.info?["giveDefaultValueKey"] {
//                paramsOthers.append(giveDefaultValueKey)
//            }
//        }
//        //遍历数组
//        for string in paramsOthers  {
//            //从allinfo中拿需要的value
//            if let value = allInfo[string] {
//                params.updateValue(value.components(separatedBy: ",").first!, forKey: string)  // 值存在直接赋值
//            }else{ //值不存在就去对照表里边找
//                guard let _ = dict["replaceList"] as? [String : String] else { //如果没有对照表，提示信息不完整
//                    self.showMessage("请完善信息后再试", success: false)
//                    return
//                }
//                let replaceList = dict["replaceList"] as! [String : String]
//                guard let _ = allInfo[replaceList[string] ?? "0"]  else { //对照表也找不到
////                    params.updateValue("", forKey: string)
////                    allInfo.updateValue("", forKey: string)//同时存入allInfo备用
//                   self.showMessage("请完善信息后再试", success: false)
//                   return
//                }
//                if let replaceValue = allInfo[replaceList[string] ?? "0"] {
//                    params.updateValue(replaceValue.components(separatedBy: ",").first!, forKey: string)
//                    allInfo.updateValue(replaceValue, forKey: string)//同时存入allInfo备用
//                }
//            }
//        }
//        
//        let constantParam = dict["constantParam"]
//        if constantParam is Dictionary<String, String> {
//            for (key , value) in (constantParam as! [String : String]){
//                params.updateValue(value, forKey: key)
//            }
//        } //参数组装完成，发起请求··
//        
//        guard soapMethodName != "oneToManyHandle" else{ //一品多码的处理
//            var piElement:String?
//            if params["piOwner"] != nil {
//                piElement = params["piOwner"]
//                guard params["piArticleCode"] != nil else {
//                    self.showMessage("请完善信息后再试", success: false)
//                    return
//                }
//                self.oneToManyHandle(params["piArticleCode"]!, piOwner: piElement, piBin: nil , success: { [weak self] _ in
//                    if methodNames.count > index + 1 {
//                        self!.requestWithMethodName(cell,methodNames: methodNames, text: self!.allInfo["内码"] ?? "", index: (index + 1) ,skip: true, success: success , field: field)
//                    }else{
//                        success!()
//                    }
//                }, faild: {
//                    field!()
//                })
//            }else{
//                piElement = params["piBin"]
//                self.oneToManyHandle(params["piArticleCode"]!, piOwner: nil, piBin: piElement, success:{ [weak self] _ in
//                    if methodNames.count > index + 1 {
//                        self!.requestWithMethodName(cell,methodNames: methodNames, text: self!.allInfo["内码"] ?? "", index: (index + 1) ,skip: true, success: success , field: field)
//                    }else{
//                        success!()
//                    }
//                    }, faild: {
//                        field!()
//                })
//            }
//            return
//        }
//        
//        guard soapMethodName != "compareElement" else{ //比较数值的处理
//            let KeysDict = cell?.info!
//            self.compareElement(KeysDict!["releationShip"]!, key1: KeysDict!["key1"]!, key2: KeysDict!["key2"]!, success: {
//                if methodNames.count > index + 1 {
//                    self.requestWithMethodName(cell, methodNames: methodNames, text: text, index: index + 1, skip: true, success: success, field: field)
//                }else{
//                    success!()
//                }
//                }, failed: {
//                    if let msg = self.allInfo["compareNoticeMsg"]{
//                        let alertControl = UIAlertController(title: "确定", message: msg, preferredStyle: UIAlertControllerStyle.alert)
//                        alertControl.addAction(UIAlertAction(title: "取消", style: UIAlertActionStyle.default, handler: { (action) in
//                            field!()
//                            alertControl.dismiss(animated: true, completion: nil)
//                        }))
//                        alertControl.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.default, handler: { [weak self] (action) in
//                            if methodNames.count > index + 1 {
//                                self!.requestWithMethodName(cell, methodNames: methodNames, text: text, index: index + 1, skip: true, success: success, field: field)
//                            }else{
//                                success!()
//                            }
//                        }))
//                        self.present(alertControl, animated: true, completion: nil)
//                        return
//                    }
//                field!()
//            })
//            return
//        }
//        
//        if soapMethodName == "resetController" { //清除屏幕的处理
//            success!()
//            self.resetController()
//            return
//        }
//        if soapMethodName == "resetControllerAlert" { //清除屏幕的处理
//            success!()
//            self.resetControllerAlert()
//            return
//        }
//        
//        guard soapMethodName != "giveDefaultValue" else{ //给予默认值得处理
//            
//            let cell1 = cell as! displayDetailProtocol
//            if !cell1.isEmpty() {
//                if methodNames.count > index + 1 {
//                    self.requestWithMethodName(cell, methodNames: methodNames, text: text, index: index + 1, skip: true, success: success, field: field)
//                }else{
//                    success!()
//                }
//                return
//            }
//            cell1.setDetail(params.values.first ?? "")
//            if methodNames.count > index + 1 {
//                self.requestWithMethodName(cell, methodNames: methodNames, text: text, index: index + 1, skip: true, success: success, field: field)
//            }else{
//                success!()
//            }
//            
//            return
//        }
//     
//        NetworkTool.sharedTools.postSoap(params as NSDictionary, bodyMethod: soapMethodName!,suffix: suffix, success: { [weak self] (data) in
//            //TODO: //请求成功
//            //把返回的数据全部存入allInfo
//            var responseDict = analysisManager.shareManager.XmlParserAnalysis(XMLParser(data: data), elementName: "\(soapMethodName!)Response").first
//            self!.allInfo += responseDict!
//            //检查执行结果，结果等于 0 ，代表成功
//            guard responseDict!["\(soapMethodName!)Result"] == "0" else{
//                field!()
//                return
//            }
//            var collections = [String]()
////            if  let dict = self!.controllerInfo?["collectionInfo"]  {
////                
////                if let Strings = dict?["collectionNames"] as? [String]{
////                    collections = Strings
////                }
////            }
//            for i in  0..<collections.count {
//                let array = collections[i].components(separatedBy: ":")
//                if array.count > 1{
//                    if array[0] == soapMethodName{
//                        let indexPath = self!.DetailListCellIndexPath[i]//寻找需要该数组的cell，传递过去
//                        let cell = self!.tableView.cellForRow(at: indexPath) as! DetailListCell
//                        cell.anyInfo = responseDict![array[1]] as AnyObject?
//                        self!.tableView.reloadData()
//                    }
//
//                }else{
//                    if collections[i] == soapMethodName{
//                        let array = analysisManager.shareManager2.XmlParserAnalysis(XMLParser(data: data), elementName: "collect")
//                        _ = self!.dictCollections?.updateValue(array, forKey: collections[i])
//                        let indexPath = self!.DetailListCellIndexPath[i]//寻找需要该数组的cell，传递过去
//                        let cell = self!.tableView.cellForRow(at: indexPath) as! DetailListCell
//                        cell.anyInfo = array as AnyObject?
//                        self!.tableView.reloadData()
//                    }
//                }
//              
//            }
//           
//            
//            if soapMethodName == "MoveInv_GetArtListByBin"{
//                let result = analysisManager.shareManager.XmlParserAnalysis(XMLParser(data: data), elementName: "collect")
//                if result.count  == 1 {  //只有一个货品的话
//                    self!.allInfo += result.first!
//                    self!.assignForKeysToDisplay()
//                    success!()
//                }else if result.count > 1{
//                    let selectorView = SelectTableView(dataArray: result)
//                    selectorView.showSelector(self!.tableView, success: { [weak self] (dict) in
//                        self!.allInfo += dict
//                        self!.assignForKeysToDisplay()
//                        if methodNames.count > index + 1 {
//                            self!.requestWithMethodName(cell,methodNames: methodNames, text: text, index: (index + 1) ,skip: true ,success: success ,field: field)
//                        }else{
//                            success!()
//                        }
//                    })
//                    return
//                }else{
//                    field!()
//                    return
//                }
//            }
//       
//            //通知进行下次请求
//            if methodNames.count > index + 1 {
//                self!.requestWithMethodName(cell,methodNames: methodNames, text: text, index: (index + 1) ,skip: true ,success: success ,field: field)
//            }else{ //所有请求已经完成，//检查是否有需要赋值
//               self!.assignForKeysToDisplay()
//                success!()
//            }
//            }) { 
//              //TODO:    //请求失败
//           
//        }
//    }
//    func assignForKeysToDisplay(){
//        for cell in self.displayCellArray{
//            let keys = cell.keyToDisplay
//            var stringToDisplay = ""
//            for key in (keys ?? "").components(separatedBy: "/"){
//                if let detail = self.allInfo[key]{
//                    stringToDisplay += (stringToDisplay == "") ? detail : ("/\(detail)")
//                }else{
//                    stringToDisplay += (stringToDisplay == "") ? "" : ("/\("")")
//                }
//            }
//            if stringToDisplay != ""{
//                cell.setDetail(stringToDisplay)
//            }
//        }
//    }
//    //MARK: - delegate & notification
//    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
//        if self.bottomView != nil{
//            self.bottomView!.y = KscreenHeight - bottomView!.height + self.tableView.contentOffset.y
//        }
//    }
//    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
//        if gestureRecognizer == self.navigationController?.interactivePopGestureRecognizer {
//            return false
//        }
//        return true
//    }
//    func updateDetail(_ value: String, forKey: String) {
//        allInfo.updateValue(value, forKey: forKey)
//        if value.components(separatedBy: "+").count == 2 {
//            let array = value.components(separatedBy: "+")
//            let number1 = (array[0] as NSString).intValue
//            let number2 = (array[1] as NSString).intValue
//            let spec = ((allInfo["poSpec"]?.components(separatedBy: "*").last)! as NSString).intValue
//            let num = number1 * spec + number2
//            allInfo.updateValue(String(num), forKey: "allNumber")
//        }
//    }
//    func clickButton(_ button: UIButton) {
//        let index = button.tag - 100
//        let dictArray = controllerInfo!["bottom"] as? [[String : String]]
//        var dict = [String : String]()
//        if dictArray!.count > index{
//            dict = dictArray![index]
//            guard dict["methodNames"] != nil else {
//                return
//            }
//            
//            let methodNames = dict["methodNames"]!.components(separatedBy: ",")
//            guard methodNames.first != "return" else{
//                if let cell = self.activedCell{
//                    self.finishInput(cell)
//                }
//                return
//            }
//            let cell = FounctionBaseCell()
//            cell.info = [String : String]()
//            cell.info! += dict
//            self.requestWithMethodName(cell,methodNames: methodNames, text: "", index: 0, skip: false, success: {
//                 //TODO: <#code#>//请求成功
//                let info = cell.info
//                if let msg = info!["successMsg"]{
//                    self.showMessage(msg, success: true)
//                }
//            }) {
//                //TODO: 失败的处理
//                self.showMessage(self.allInfo["poErrMsg"]!, success: false)
//                let cell = self.activedCell
//                if cell!.info!["errorNext"] != nil {
//                    self.goToErrorNextCell(self.activedCell!)
//                    return
//                }else{
//                    (cell as? inputViewProtocol)?.state = inputViewState.wrong
//                }
//               
//            }
//        }
//    }
//    func resetControllerAlert(){
//        if let cell = self.tableView.cellForRow(at: self.firstIndexPath!) as? displayDetailProtocol {
//            if cell.isEmpty() {
//                return
//            }
//        }
//        let alertControl = UIAlertController(title: "确定", message: "确定清除所有信息吗?", preferredStyle: UIAlertControllerStyle.alert)
//        alertControl.addAction(UIAlertAction(title: "取消", style: UIAlertActionStyle.default, handler: { (action) in
//            return
//        }))
//        alertControl.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.default, handler: { [weak self] (action) in
//            let activeCell = self!.activedCell as? inputViewProtocol
//            activeCell?.state = inputViewState.disabled
//            self!.reuseAble = false
//            self!.tableView.reloadData()
//            self!.allInfo = ["piOperator" : (userInfo?.userName)!, "piUser" : (userInfo?.userName)! , "piType" : "0"]
//            self!.tableView.isUserInteractionEnabled = true
//            self!.bottomView?.isUserInteractionEnabled = true
//            let cell = self!.tableView.cellForRow(at: self!.firstIndexPath!) as? inputViewProtocol
//            cell?.state = inputViewState.activated
//            self!.activedCell = cell as? FounctionBaseCell
//        }))
//        self.present(alertControl, animated: true, completion: nil)
//    }
//    func resetController(){
//            let activeCell = self.activedCell as? inputViewProtocol
//            activeCell?.state = inputViewState.disabled
//            self.reuseAble = false
//            self.tableView.reloadData()
//            self.allInfo = ["piOperator" : (userInfo?.userName)!, "piUser" : (userInfo?.userName)! , "piType" : "0"]
//            self.tableView.isUserInteractionEnabled = true
//            self.bottomView?.isUserInteractionEnabled = true
//            let cell = self.tableView.cellForRow(at: self.firstIndexPath!) as? inputViewProtocol
//            cell?.state = inputViewState.activated
//            self.activedCell = cell as? FounctionBaseCell
//    }
//    func finishUpdateDetail(_ cell: FounctionBaseCell) {
//        
//        let info = cell.info
//        if let indexStringArray = info!["next"]?.components(separatedBy: ","){
//            let section = Int((indexStringArray.first)!)
//            let row = Int((indexStringArray.last)!)
//            let indexPath = IndexPath(row: row!, section: section!)
//            let cell = cell as! inputViewProtocol
//            cell.state = inputViewState.disabled
//            let nextCell = self.tableView.cellForRow(at: indexPath) as? inputViewProtocol
//            nextCell?.state = inputViewState.activated
//            self.activedCell = nextCell as? FounctionBaseCell
//            return
//        }
//        let methodname = info!["methodName"]
//        let methodNames = methodname?.components(separatedBy: ",")
//        requestWithMethodName(cell,methodNames: methodNames ?? ["updStkin"], text: "", index: 0, skip: false, success: {
////            SVProgressHUD.showSuccessWithStatus("收货成功")
//            self.showMessage("收货成功", success: true)
//            let cell = cell as! inputViewProtocol
//            cell.state = inputViewState.disabled
//            self.bottomView?.isUserInteractionEnabled = true
////            self.tableView.userInteractionEnabled = false
//        }){
//             //TODO: 失败的处理
//            if self.allInfo["errorNext"] != nil {
//                self.goToErrorNextCell(cell)
//                return
//            }
//            self.showMessage(self.allInfo["poErrMsg"] ?? "错误", success: false)
//            let cell = cell as? inputViewProtocol
//            cell?.state = inputViewState.wrong
//        }
//    }
//    func finishInput(_ cell: FounctionBaseCell) {
//         //TODO: 输入完成，检查数据
//        (cell as? inputViewProtocol)?.state = .disabled
//        self.reuseAble = true
//        let info = cell.info!
//        let methodNamesString = info["methodName"]!
//        let methodNames = methodNamesString.components(separatedBy: ",")
////        let indexStringArray = info["next"]?.componentsSeparatedByString(",")
////        let section = Int((indexStringArray?.first) ?? "-1")
////        let row = Int((indexStringArray?.last) ?? "-1")
////        let indexPath = NSIndexPath(forRow: row!, inSection: section!)//读取需要跳转的下一个indexPath
////        let text = info["keyToUpdate"]?.componentsSeparatedByString(",").first
//        self.requestWithMethodName(cell,methodNames: methodNames, text: "", index: 0, skip: true , success:{
//            if let msg = info["successMsg"]{
//                self.showMessage(msg, success: true)
//            }
//            self.goToNextCell(cell)
////            let cell = cell as! inputViewProtocol
////            cell.state = inputViewState.disabled
////            if indexPath.row != -1{
////                let nextCell = self.tableView.cellForRowAtIndexPath(indexPath) as? inputViewProtocol
////                nextCell?.state = inputViewState.activated
////            }else{ //代表已经结束了
////                
////            }
//        }){
//            self.showMessage(self.allInfo["poErrMsg"] ?? "错误", success: false)
//            if info["errorNext"] != nil {
//                self.goToErrorNextCell(cell)
//                return
//            }else{
//                let cell = cell as? inputViewProtocol
//                cell?.state = inputViewState.wrong
//            }
//        }
//
//    }
//    
//    func finishDateInput(_ notification: Notification){
//        let cell = notification.object as! DatePickerCell
//        let dateInProduced = cell.date
//        let formeter = DateFormatter()
//        formeter.dateFormat = "yyyy-MM-dd"
//        guard let _ = allInfo["poValidPeriod"] else{
//            return
//        }
//       let qualityDate = (allInfo["poValidPeriod"]! as NSString).doubleValue
//        let remainDay = qualityDate - (Date().timeIntervalSince(dateInProduced) / 86400.0) //剩余保质期
//        if remainDay > (allInfo["poDateChkStd"]! as NSString).doubleValue{//拿来和收货控制天数比较
//            //进行下一步
//            NetworkTool.sharedTools.postSoap(["piArticle" : allInfo["piArticle"] ?? "", "piDate" : formeter.string(from: dateInProduced)], bodyMethod: "chkDateIsLatest",suffix:nil, success: { [weak self] (data) in
//                let resultDict = analysisManager.shareManager.XmlParserAnalysis(XMLParser(data: data), elementName: "chkDateIsLatestResponse").first
//                if resultDict!["chkDateIsLatestResult"] == "0" {
//                    //赋值PiLot
//                    let formeter2 = DateFormatter()
//                    formeter2.dateFormat = "yyyyMMdd"
//                    self!.allInfo.updateValue(formeter2.string(from: dateInProduced), forKey: "piLot")
//                    self!.allInfo.updateValue(formeter.string(from: dateInProduced), forKey: "piDate")
//                    self!.assignForKeysToDisplay()
//                    self!.goToNextCell(cell)
//                }else{
//                    let alertControl = UIAlertController(title: "确定", message: "确定使用该日期吗?", preferredStyle: UIAlertControllerStyle.alert)
//                    alertControl.addAction(UIAlertAction(title: "取消", style: UIAlertActionStyle.default, handler: { (action) in
//                        cell.state = inputViewState.wrong
//                        alertControl.dismiss(animated: true, completion: nil)
//                    }))
//                    alertControl.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.default, handler: { [weak self] (action) in
//                       self!.goToNextCell(cell)
//                    }))
//                    self!.present(alertControl, animated: true, completion: nil)
//                }
//                }, failed: {
//                    self.showMessage("网络失败", success: false)
//            })
//        }else{ //否则返回，重新输入
//            self.showMessage("请重新输入日期", success: false)
//            cell.state = .wrong
//            return
//        }
//        //发起网络请求
//        
//    }
//    //MARK: - UITableViewDataSource
//    override func numberOfSections(in tableView: UITableView) -> Int {
//        return self.dataArray?.count ?? 0
//    }
//    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//        return self.dataArray![section].count
//    }
//    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//        
//        if let cell = cellDictionary["\(indexPath)"] {
//            if self.reuseAble == false{//是否清除数据
//                cell.clearContent()
//            }
//            return cell
//        }
//        let infoDict = self.dataArray![(indexPath as NSIndexPath).section][(indexPath as NSIndexPath).row]
//        let modelType = infoDict[FounctionCellsModel.cellType] ?? FounctionCellType.productInfo.rawValue
//        allInfo += infoDict
//        let cellType = stringClassFromString(modelType) as! FounctionBaseCell.Type
//        let cell = cellType.init()
////        if indexPath.row == 0{
////            cell.titleView.font = UIFont.boldSystemFontOfSize(15)
////            cell.separatorView.hidden = false
////        }
//        cell.setValue(infoDict, forKey: "info")
//        if let inputCell = (cell as? inputViewProtocol) {
//            //TODO: 以后修改，避免直接暴力赋值
//            inputCell.delegate = self
//        }
//        if cell is displayDetailProtocol {
//            self.displayCellArray.append(cell as! displayDetailProtocol)
//        }
//        if let inputCell = (cell as? NumberInputCell) {
//            //TODO: 以后修改，避免直接暴力赋值
//            inputCell.delegateDetailUpdate = self
//        }
//        let indexPathString = "\(indexPath)"
//        cellDictionary.updateValue(cell, forKey: indexPathString)
//        return cell
//    }
//    
//    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//        if let headers = self.sectionHeaders {
//            if headers[section].characters.count > 0{
//                let view = FounctionSectionHeaderView(headerString: headers[section])
//                return view
//            }
//        }
//        return nil
//    }
//    //MARK: - UITableViewDelegate
//    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//        guard self.DetailListCellIndexPath.count > 0 else{
//            return 44
//        }
//        for path in self.DetailListCellIndexPath {
//            if path == indexPath{
//                let cell = cellDictionary[String(describing: indexPath)] as? DetailListCell//取出需要计算行高的cell
//                let height = cell?.realHeight ?? 44
//                return CGFloat(height)
//            }
//        }
//        return 44
//    }
//    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
//        if let headers = self.sectionHeaders {
//            if headers[section].characters.count > 0{
//                return 40
//            }
//        }
//        if section == 0 { //如果不需要显示文字，首行5点高度
//            return 0
//        }else{
//            return 10
//        }
//    }
//    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
//        if let array = self.sectionFooters{
//            let flag = array[section]
//            if flag == "true" {
//                return 15
//            }
//        }
//        return 0.1
//    }
////    override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
////        let view = UIView(frame: CGRect(x: 0, y: 0, width: KscreenWidth, height: 100))
////        return view
////    }
//    
//    
//
//    //MARK: - lazyLoading
//    lazy fileprivate var bottomView:FounctionBottomView? = {
//        if self.bottomItems == nil{
//            return nil
//        }
//        let view = FounctionBottomView(array: self.bottomItems!)
//        return view
//    }()
//    
//    deinit{
//        self.tableView.endEditing(true)
//        print("销毁了---------------------------------------------------")
//    }
//}
//
//
